package com.iwhalecloud.bss.kite.cucc.service.attr.handler;

import com.iwhalecloud.bss.kite.common.util.KiteStringUtils;
import com.iwhalecloud.bss.kite.cucc.common.constant.LocalKeyConsts;
import com.iwhalecloud.bss.kite.manager.inst.KiteAttr;
import com.iwhalecloud.bss.kite.manager.inst.KiteInst;
import com.iwhalecloud.bss.kite.service.attr.AttrData;
import com.iwhalecloud.bss.kite.service.attr.handler.AbstractAttrHandler;
import com.iwhalecloud.bss.kite.service.scene.attr.OperateInstAttrService;
import org.springframework.beans.factory.annotation.Autowired;

/**
 * 共享型5G专网接入方式
 */
public class Shared5GAccessModeAttrHandler extends AbstractAttrHandler<KiteInst, AttrData> {

    @Autowired
    OperateInstAttrService operateInstAttrService;

    @Override
    public void set(KiteAttr attr, KiteInst inst, String value, AttrData data) {
        super.set(attr, inst, value, data);

        if(KiteStringUtils.isBlank(inst.getSpecId()) || !KiteStringUtils.equals(inst.getSpecId(),"100000000017328")) { //数据分流服务
            return;
        }else {//
            //L2TP隧道key
            KiteAttr l2tpAttr = inst.getAttr("200004504");
            //共享平台客户内网路由
            KiteAttr sharedCustomerIntranetRoutingAttr = inst.getAttr("200004505");
            //共享平台增值服务
            KiteAttr sharedValuaddServicesAttr = inst.getAttr("200004506");

            if (KiteStringUtils.isNotBlank(value) && KiteStringUtils.equals(value, "100006702")) { //GRE隧道方式
                l2tpAttr.setValue("");
                l2tpAttr.setValueDesc("");
                l2tpAttr.setShowType(LocalKeyConsts.PROD_ATTR_SHOW_TYPE_H);
                sharedCustomerIntranetRoutingAttr.setValue("");
                sharedCustomerIntranetRoutingAttr.setValueDesc("");
                sharedCustomerIntranetRoutingAttr.setShowType(LocalKeyConsts.PROD_ATTR_SHOW_TYPE_H);
                sharedValuaddServicesAttr.setValue("");
                sharedValuaddServicesAttr.setValueDesc("");
                sharedValuaddServicesAttr.setShowType(LocalKeyConsts.PROD_ATTR_SHOW_TYPE_H);
            } else if (KiteStringUtils.isNotBlank(value) && KiteStringUtils.equals(value,"100006703")) { //L2TP隧道方式
                l2tpAttr.setShowType(LocalKeyConsts.PROD_ATTR_SHOW_TYPE_D);
                sharedCustomerIntranetRoutingAttr.setValue("");
                sharedCustomerIntranetRoutingAttr.setValueDesc("");
                sharedCustomerIntranetRoutingAttr.setShowType(LocalKeyConsts.PROD_ATTR_SHOW_TYPE_H);
                sharedValuaddServicesAttr.setValue("");
                sharedValuaddServicesAttr.setValueDesc("");
                sharedValuaddServicesAttr.setShowType(LocalKeyConsts.PROD_ATTR_SHOW_TYPE_H);
            } else if(KiteStringUtils.isNotBlank(value) && KiteStringUtils.equals(value,"100008021")) { //共享平台
                l2tpAttr.setValue("");
                l2tpAttr.setValueDesc("");
                l2tpAttr.setShowType(LocalKeyConsts.PROD_ATTR_SHOW_TYPE_H);
                sharedCustomerIntranetRoutingAttr.setShowType(LocalKeyConsts.PROD_ATTR_SHOW_TYPE_D);
                sharedValuaddServicesAttr.setShowType(LocalKeyConsts.PROD_ATTR_SHOW_TYPE_D);
            }

            operateInstAttrService.setAttrValue(inst, "200004504", l2tpAttr.getValue(), data.getSceneInstId(), null);
            operateInstAttrService.setAttrValue(inst, "200004505", sharedCustomerIntranetRoutingAttr.getValue(), data.getSceneInstId(), null);
            operateInstAttrService.setAttrValue(inst, "200004506", sharedValuaddServicesAttr.getValue(), data.getSceneInstId(), null);
        }
    }
}
